.class public Lcom/tendcloud/tenddata/o;
.super Lcom/tendcloud/tenddata/l;


# static fields
.field public static final f:B = 0xdt

.field public static final g:B = 0xat

.field public static final h:B = 0x0t

.field public static final i:B = -0x1t


# instance fields
.field protected j:Z

.field protected k:Ljava/util/List;

.field protected l:Ljava/nio/ByteBuffer;

.field private final m:Ljava/util/Random;


# direct methods
.method public constructor <init>()V
    .locals 1

    invoke-direct {p0}, Lcom/tendcloud/tenddata/l;-><init>()V

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/tendcloud/tenddata/o;->j:Z

    new-instance v0, Ljava/util/LinkedList;

    invoke-direct {v0}, Ljava/util/LinkedList;-><init>()V

    iput-object v0, p0, Lcom/tendcloud/tenddata/o;->k:Ljava/util/List;

    new-instance v0, Ljava/util/Random;

    invoke-direct {v0}, Ljava/util/Random;-><init>()V

    iput-object v0, p0, Lcom/tendcloud/tenddata/o;->m:Ljava/util/Random;

    return-void
.end method


# virtual methods
.method public a(Lcom/tendcloud/tenddata/ah;)Lcom/tendcloud/tenddata/ah;
    .locals 3

    const-string v0, "Upgrade"

    const-string v1, "WebSocket"

    invoke-interface {p1, v0, v1}, Lcom/tendcloud/tenddata/ah;->a(Ljava/lang/String;Ljava/lang/String;)V

    const-string v0, "Connection"

    const-string v1, "Upgrade"

    invoke-interface {p1, v0, v1}, Lcom/tendcloud/tenddata/ah;->a(Ljava/lang/String;Ljava/lang/String;)V

    const-string v0, "Origin"

    invoke-interface {p1, v0}, Lcom/tendcloud/tenddata/ah;->b(Ljava/lang/String;)Z

    move-result v0

    if-nez v0, :cond_0

    const-string v0, "Origin"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "random"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->m:Ljava/util/Random;

    invoke-virtual {v2}, Ljava/util/Random;->nextInt()I

    move-result v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-interface {p1, v0, v1}, Lcom/tendcloud/tenddata/ah;->a(Ljava/lang/String;Ljava/lang/String;)V

    :cond_0
    return-object p1
.end method

.method public a(Lcom/tendcloud/tenddata/af;Lcom/tendcloud/tenddata/ap;)Lcom/tendcloud/tenddata/ai;
    .locals 2

    const-string v0, "Web Socket Protocol Handshake"

    invoke-interface {p2, v0}, Lcom/tendcloud/tenddata/ap;->setHttpStatusMessage(Ljava/lang/String;)V

    const-string v0, "Upgrade"

    const-string v1, "WebSocket"

    invoke-interface {p2, v0, v1}, Lcom/tendcloud/tenddata/ap;->a(Ljava/lang/String;Ljava/lang/String;)V

    const-string v0, "Connection"

    const-string v1, "Connection"

    invoke-interface {p1, v1}, Lcom/tendcloud/tenddata/af;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-interface {p2, v0, v1}, Lcom/tendcloud/tenddata/ap;->a(Ljava/lang/String;Ljava/lang/String;)V

    const-string v0, "WebSocket-Origin"

    const-string v1, "Origin"

    invoke-interface {p1, v1}, Lcom/tendcloud/tenddata/af;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-interface {p2, v0, v1}, Lcom/tendcloud/tenddata/ap;->a(Ljava/lang/String;Ljava/lang/String;)V

    new-instance v0, Ljava/lang/StringBuilder;

    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V

    const-string v1, "ws://"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    const-string v1, "Host"

    invoke-interface {p1, v1}, Lcom/tendcloud/tenddata/af;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-interface {p1}, Lcom/tendcloud/tenddata/af;->a()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    const-string v1, "WebSocket-Location"

    invoke-interface {p2, v1, v0}, Lcom/tendcloud/tenddata/ap;->a(Ljava/lang/String;Ljava/lang/String;)V

    return-object p2
.end method

.method public a(Lcom/tendcloud/tenddata/af;)Lcom/tendcloud/tenddata/l$b;
    .locals 1

    const-string v0, "Origin"

    invoke-interface {p1, v0}, Lcom/tendcloud/tenddata/af;->b(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    invoke-virtual {p0, p1}, Lcom/tendcloud/tenddata/o;->a(Lcom/tendcloud/tenddata/al;)Z

    move-result v0

    if-eqz v0, :cond_0

    sget-object v0, Lcom/tendcloud/tenddata/l$b;->a:Lcom/tendcloud/tenddata/l$b;

    :goto_0
    return-object v0

    :cond_0
    sget-object v0, Lcom/tendcloud/tenddata/l$b;->b:Lcom/tendcloud/tenddata/l$b;

    goto :goto_0
.end method

.method public a(Lcom/tendcloud/tenddata/af;Lcom/tendcloud/tenddata/an;)Lcom/tendcloud/tenddata/l$b;
    .locals 2

    const-string v0, "WebSocket-Origin"

    invoke-interface {p1, v0}, Lcom/tendcloud/tenddata/af;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    const-string v1, "Origin"

    invoke-interface {p2, v1}, Lcom/tendcloud/tenddata/an;->a(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    invoke-virtual {p0, p2}, Lcom/tendcloud/tenddata/o;->a(Lcom/tendcloud/tenddata/al;)Z

    move-result v0

    if-eqz v0, :cond_0

    sget-object v0, Lcom/tendcloud/tenddata/l$b;->a:Lcom/tendcloud/tenddata/l$b;

    :goto_0
    return-object v0

    :cond_0
    sget-object v0, Lcom/tendcloud/tenddata/l$b;->b:Lcom/tendcloud/tenddata/l$b;

    goto :goto_0
.end method

.method public a(Lcom/tendcloud/tenddata/ad;)Ljava/nio/ByteBuffer;
    .locals 3

    invoke-interface {p1}, Lcom/tendcloud/tenddata/ad;->f()Lcom/tendcloud/tenddata/ad$a;

    move-result-object v0

    sget-object v1, Lcom/tendcloud/tenddata/ad$a;->b:Lcom/tendcloud/tenddata/ad$a;

    if-eq v0, v1, :cond_0

    new-instance v0, Ljava/lang/RuntimeException;

    const-string v1, "only text frames supported"

    invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v0

    :cond_0
    invoke-interface {p1}, Lcom/tendcloud/tenddata/ad;->c()Ljava/nio/ByteBuffer;

    move-result-object v0

    invoke-virtual {v0}, Ljava/nio/ByteBuffer;->remaining()I

    move-result v1

    add-int/lit8 v1, v1, 0x2

    invoke-static {v1}, Ljava/nio/ByteBuffer;->allocate(I)Ljava/nio/ByteBuffer;

    move-result-object v1

    const/4 v2, 0x0

    invoke-virtual {v1, v2}, Ljava/nio/ByteBuffer;->put(B)Ljava/nio/ByteBuffer;

    invoke-virtual {v0}, Ljava/nio/ByteBuffer;->mark()Ljava/nio/Buffer;

    invoke-virtual {v1, v0}, Ljava/nio/ByteBuffer;->put(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;

    invoke-virtual {v0}, Ljava/nio/ByteBuffer;->reset()Ljava/nio/Buffer;

    const/4 v0, -0x1

    invoke-virtual {v1, v0}, Ljava/nio/ByteBuffer;->put(B)Ljava/nio/ByteBuffer;

    invoke-virtual {v1}, Ljava/nio/ByteBuffer;->flip()Ljava/nio/Buffer;

    return-object v1
.end method

.method public a(Ljava/lang/String;Z)Ljava/util/List;
    .locals 2

    new-instance v0, Lcom/tendcloud/tenddata/ae;

    invoke-direct {v0}, Lcom/tendcloud/tenddata/ae;-><init>()V

    :try_start_0
    invoke-static {p1}, Lcom/tendcloud/tenddata/aw;->a(Ljava/lang/String;)[B

    move-result-object v1

    invoke-static {v1}, Ljava/nio/ByteBuffer;->wrap([B)Ljava/nio/ByteBuffer;

    move-result-object v1

    invoke-interface {v0, v1}, Lcom/tendcloud/tenddata/ac;->setPayload(Ljava/nio/ByteBuffer;)V
    :try_end_0
    .catch Lcom/tendcloud/tenddata/r; {:try_start_0 .. :try_end_0} :catch_0

    const/4 v1, 0x1

    invoke-interface {v0, v1}, Lcom/tendcloud/tenddata/ac;->setFin(Z)V

    sget-object v1, Lcom/tendcloud/tenddata/ad$a;->b:Lcom/tendcloud/tenddata/ad$a;

    invoke-interface {v0, v1}, Lcom/tendcloud/tenddata/ac;->setOptcode(Lcom/tendcloud/tenddata/ad$a;)V

    invoke-interface {v0, p2}, Lcom/tendcloud/tenddata/ac;->setTransferemasked(Z)V

    invoke-static {v0}, Ljava/util/Collections;->singletonList(Ljava/lang/Object;)Ljava/util/List;

    move-result-object v0

    return-object v0

    :catch_0
    move-exception v0

    new-instance v1, Lcom/tendcloud/tenddata/w;

    invoke-direct {v1, v0}, Lcom/tendcloud/tenddata/w;-><init>(Ljava/lang/Throwable;)V

    throw v1
.end method

.method public a(Ljava/nio/ByteBuffer;Z)Ljava/util/List;
    .locals 2

    new-instance v0, Ljava/lang/RuntimeException;

    const-string v1, "not yet implemented"

    invoke-direct {v0, v1}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;)V

    throw v0
.end method

.method public a()V
    .locals 1

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/tendcloud/tenddata/o;->j:Z

    const/4 v0, 0x0

    iput-object v0, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    return-void
.end method

.method public b()Lcom/tendcloud/tenddata/l$a;
    .locals 1

    sget-object v0, Lcom/tendcloud/tenddata/l$a;->a:Lcom/tendcloud/tenddata/l$a;

    return-object v0
.end method

.method public c()Lcom/tendcloud/tenddata/l;
    .locals 1

    new-instance v0, Lcom/tendcloud/tenddata/o;

    invoke-direct {v0}, Lcom/tendcloud/tenddata/o;-><init>()V

    return-object v0
.end method

.method public c(Ljava/nio/ByteBuffer;)Ljava/util/List;
    .locals 2

    invoke-virtual {p0, p1}, Lcom/tendcloud/tenddata/o;->e(Ljava/nio/ByteBuffer;)Ljava/util/List;

    move-result-object v0

    if-nez v0, :cond_0

    new-instance v0, Lcom/tendcloud/tenddata/r;

    const/16 v1, 0x3ea

    invoke-direct {v0, v1}, Lcom/tendcloud/tenddata/r;-><init>(I)V

    throw v0

    :cond_0
    return-object v0
.end method

.method public e()Ljava/nio/ByteBuffer;
    .locals 1

    sget v0, Lcom/tendcloud/tenddata/o;->b:I

    invoke-static {v0}, Ljava/nio/ByteBuffer;->allocate(I)Ljava/nio/ByteBuffer;

    move-result-object v0

    return-object v0
.end method

.method protected e(Ljava/nio/ByteBuffer;)Ljava/util/List;
    .locals 4

    const/4 v0, 0x0

    const/4 v3, 0x1

    :goto_0
    invoke-virtual {p1}, Ljava/nio/ByteBuffer;->hasRemaining()Z

    move-result v1

    if-eqz v1, :cond_7

    invoke-virtual {p1}, Ljava/nio/ByteBuffer;->get()B

    move-result v1

    if-nez v1, :cond_1

    iget-boolean v1, p0, Lcom/tendcloud/tenddata/o;->j:Z

    if-eqz v1, :cond_0

    new-instance v0, Lcom/tendcloud/tenddata/s;

    const-string v1, "unexpected START_OF_FRAME"

    invoke-direct {v0, v1}, Lcom/tendcloud/tenddata/s;-><init>(Ljava/lang/String;)V

    throw v0

    :cond_0
    iput-boolean v3, p0, Lcom/tendcloud/tenddata/o;->j:Z

    goto :goto_0

    :cond_1
    const/4 v2, -0x1

    if-ne v1, v2, :cond_4

    iget-boolean v1, p0, Lcom/tendcloud/tenddata/o;->j:Z

    if-nez v1, :cond_2

    new-instance v0, Lcom/tendcloud/tenddata/s;

    const-string v1, "unexpected END_OF_FRAME"

    invoke-direct {v0, v1}, Lcom/tendcloud/tenddata/s;-><init>(Ljava/lang/String;)V

    throw v0

    :cond_2
    iget-object v1, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    if-eqz v1, :cond_3

    iget-object v1, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {v1}, Ljava/nio/ByteBuffer;->flip()Ljava/nio/Buffer;

    new-instance v1, Lcom/tendcloud/tenddata/ae;

    invoke-direct {v1}, Lcom/tendcloud/tenddata/ae;-><init>()V

    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {v1, v2}, Lcom/tendcloud/tenddata/ae;->setPayload(Ljava/nio/ByteBuffer;)V

    invoke-virtual {v1, v3}, Lcom/tendcloud/tenddata/ae;->setFin(Z)V

    sget-object v2, Lcom/tendcloud/tenddata/ad$a;->b:Lcom/tendcloud/tenddata/ad$a;

    invoke-virtual {v1, v2}, Lcom/tendcloud/tenddata/ae;->setOptcode(Lcom/tendcloud/tenddata/ad$a;)V

    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->k:Ljava/util/List;

    invoke-interface {v2, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    iput-object v0, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {p1}, Ljava/nio/ByteBuffer;->mark()Ljava/nio/Buffer;

    :cond_3
    const/4 v1, 0x0

    iput-boolean v1, p0, Lcom/tendcloud/tenddata/o;->j:Z

    goto :goto_0

    :cond_4
    iget-boolean v2, p0, Lcom/tendcloud/tenddata/o;->j:Z

    if-eqz v2, :cond_8

    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    if-nez v2, :cond_6

    invoke-virtual {p0}, Lcom/tendcloud/tenddata/o;->e()Ljava/nio/ByteBuffer;

    move-result-object v2

    iput-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    :cond_5
    :goto_1
    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {v2, v1}, Ljava/nio/ByteBuffer;->put(B)Ljava/nio/ByteBuffer;

    goto :goto_0

    :cond_6
    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {v2}, Ljava/nio/ByteBuffer;->hasRemaining()Z

    move-result v2

    if-nez v2, :cond_5

    iget-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    invoke-virtual {p0, v2}, Lcom/tendcloud/tenddata/o;->f(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;

    move-result-object v2

    iput-object v2, p0, Lcom/tendcloud/tenddata/o;->l:Ljava/nio/ByteBuffer;

    goto :goto_1

    :cond_7
    iget-object v0, p0, Lcom/tendcloud/tenddata/o;->k:Ljava/util/List;

    new-instance v1, Ljava/util/LinkedList;

    invoke-direct {v1}, Ljava/util/LinkedList;-><init>()V

    iput-object v1, p0, Lcom/tendcloud/tenddata/o;->k:Ljava/util/List;

    :cond_8
    return-object v0
.end method

.method public f(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;
    .locals 1

    invoke-virtual {p1}, Ljava/nio/ByteBuffer;->flip()Ljava/nio/Buffer;

    invoke-virtual {p1}, Ljava/nio/ByteBuffer;->capacity()I

    move-result v0

    mul-int/lit8 v0, v0, 0x2

    invoke-virtual {p0, v0}, Lcom/tendcloud/tenddata/o;->a(I)I

    move-result v0

    invoke-static {v0}, Ljava/nio/ByteBuffer;->allocate(I)Ljava/nio/ByteBuffer;

    move-result-object v0

    invoke-virtual {v0, p1}, Ljava/nio/ByteBuffer;->put(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;

    return-object v0
.end method
